/*
 Thay thế hàm alert và confirm mặc định
*/
function alert(text,title,option){
    _title = title ? title : 'Thông báo';
    _option = {
        callback:function(){
            
        }
    };
    $.extend(_option, option);

    absH = $(document).height();
    var body = $('body');
    overlay = '<div class="myconlert-overlay"></div>';
    popHeader = '<div class="myconlert-header">'+_title+'</div>';
    popContent = '<div class="myconlert-inner">'+text+'</div>';
    popBottom = '<div class="myconlert-bottom"><button class="myconlert-close cbtn">OK</button></div>';
    container = '<div class= "myconlert-container">'+popHeader+popContent+popBottom+'</div>';
    body.append(overlay);
    body.append(container);
    //tinh position
    //Sua lai cach tinh vi tri position
    // var pTop = ($(window).height() - $('.myconlert-container').height())/2;
    // var pLeft = ($(window).width() - $('.myconlert-container').width())/2;
    
    $('.myconlert-overlay').height(absH);
    // $('.myconlert-container').css({
    //     left:pLeft
    // }).animate({
    //     top:pTop,
    //     opacity:1
    // },300);

    //Sua lai vi tri cua alert
    $('.myconlert-container').css({
        left:'50%',
        marginLeft : -($('.myconlert-container').width()/2)
    }).animate({
        top:'50%',
        marginTop : -($('.myconlert-container').height()/2),
        opacity:1
    },300);
    var closeEvent = function(){
        $('.myconlert-container').animate({
            top:(0-$('.myconlert-container').height()),
            opacity:0
        },300,function(){
            $(this).remove();
        });
        $('.myconlert-overlay').remove();
    }
    $('.myconlert-close').click(function(){
        closeEvent();
        _option.callback();
    });
    $('.myconlert-overlay').click(function(){
        closeEvent();
        _option.callback();
    })
    $(window).focus().keypress(function(e){
        if(e.keyCode == 13 || e.keyCode == 27){
            closeEvent();
            _option.callback();
        }
    });
}